package com.lz.football.module.guess
{
	import com.common.utils.Reflection;
	import com.global.GlobalDef;
	import com.liangzhong.events.GuessEvent;
	import com.liangzhong.model.AppData;
	import com.liangzhong.model.footballLottery.vo.GuessDetailVo;
	import com.liangzhong.model.footballLottery.vo.GuessVo;
	import com.lz.football.module.base.IComponent;
	
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import lz.controls.Alert;
	import lz.controls.RadioButton;
	import lz.controls.core.UIComponent;
	import lz.controls.managers.PopUpManager;

	/**
	 *押注 结果面板 
	 * @author lake
	 * 
	 */	
	public class BetResultPanel extends UIComponent implements IComponent
	{
		/**
		 *确认 
		 */		
		private var sureBtn 			:SimpleButton;
		/**
		 *选择组容器 
		 */		
		private var radioContainer 	:Sprite;
		/**
		 *标题文本 
		 */		
		private var txtTitle			:TextField;
		/**
		 *赢赔率文本 
		 */		
		private var txtWin				:TextField;
		/**
		 *和赔率文本 
		 */		
		private var txtTie				:TextField;
		/**
		 *输赔率文本 
		 */		
		private var txtLose			:TextField;
		/**
		 *点券下注输入框 
		 */		
		private var txtCashValue		:TextField;
		/**
		 *欧元下注输入框 
		 */		
		private var txtCoinValue		:TextField;
		/**
		 *点券下注按钮 
		 */		
		private var cashBetBtn			:SimpleButton;
		/**
		 *欧元下注按钮 
		 */		
		private var coinBetBtn			:SimpleButton;
		/**
		 *data 
		 */		
		private var _data			:*;
		/**
		 * 球队1详情
		 */		
		private var txtDesc1		:TextField;
		/**
		 *  球队2详情
		 */		
		private var txtDesc2		:TextField;
		/**
		 * 球队1详情按钮
		 */		
		private var detailBtn1		:SimpleButton;
		/**
		 * 球队2详情按钮
		 */		
		private var detailBtn2		:SimpleButton;
		/**
		 * 输和赢radiobutton
		 */		
		private var winRadioBtn 	:RadioButton;
		private var tieRadioBtn 	:RadioButton;
		private var lostRadioBtn	:RadioButton;
		/**
		 *球队详情面板 
		 */		
		private var teamDetailPanel	:TeamDetailPanel;
		/**
		 *是否点券押注 
		 */		
		private var isCashBet			:Boolean = false;
		
		public function BetResultPanel()
		{
			super();
		}
		/**
		 *获取设置数据 
		 * @param value
		 * 
		 */		
		public function set data(value:*):void
		{
			_data = value;
			if(_data == null)
			{
				return;
			}
			var guessDetail :GuessVo = _data;
			if(guessDetail.status == 1)//竞猜中
			{
			}
			else
			{
			}
			txtTitle.htmlText = guessDetail.descplay + "";
			txtWin.htmlText = guessDetail.odds1 + "";
			txtTie.htmlText = guessDetail.odds2 + "";
			txtLose.htmlText = guessDetail.odds3 + "";
			winRadioBtn.label = guessDetail.huname + "胜";
			lostRadioBtn.label = guessDetail.guname + "胜";
			tieRadioBtn.label = "两队平";
			winRadioBtn.labelTxt.textColor = 0xCCCCCC;
			lostRadioBtn.labelTxt.textColor = 0xCCCCCC;
			tieRadioBtn.labelTxt.textColor = 0xCCCCCC;
			txtDesc1.htmlText = guessDetail.hdescplay + "";
			txtDesc2.htmlText = guessDetail.gdescplay + "";
		}
		public function get data():*
		{
			return _data;
		}
		/**
		 * 初始化
		 * @param view
		 */		
		public function initUI(view:Object=null):void
		{
			_symbolSkin = Reflection.createInstance("com.lz.res.fbLottery.BetResultSKin");
			sureBtn = _symbolSkin.sureBtn;
			radioContainer = new Sprite();
			_symbolSkin.addChild(radioContainer);
			radioContainer.x = 188;
			radioContainer.y = 89;
			txtCashValue = _symbolSkin.txtCashValue;
			txtCoinValue = _symbolSkin.txtCoinValue;
			txtCashValue.text = "10";
			txtCoinValue.text = "100000";
			cashBetBtn = _symbolSkin.cashBetBtn;
			coinBetBtn = _symbolSkin.coinBetBtn;
			this.addChild(_symbolSkin);
			winRadioBtn = new RadioButton();
			winRadioBtn.skin = "guess.SkinCheckBox";
			winRadioBtn.label = "中国";
			winRadioBtn.width = 180;
			winRadioBtn.x = 0;
			winRadioBtn.y = 0;
			winRadioBtn.labelTxt.textColor = 0xCCCCCC;
			winRadioBtn.value = 1;
			radioContainer.addChild(winRadioBtn);
			tieRadioBtn = new RadioButton();
			tieRadioBtn.skin = "guess.SkinCheckBox";
			tieRadioBtn.label = "两队平";
			tieRadioBtn.width = 180;
			tieRadioBtn.x = 0;
			tieRadioBtn.y = 38;
			tieRadioBtn.value = 2;
			tieRadioBtn.labelTxt.textColor = 0xCCCCCC;
			radioContainer.addChild(tieRadioBtn);
			lostRadioBtn = new RadioButton();
			lostRadioBtn.skin = "guess.SkinCheckBox";
			lostRadioBtn.label = "美国";
			lostRadioBtn.width = 180;
			lostRadioBtn.x = 0;
			lostRadioBtn.y = 77;
			lostRadioBtn.value = 3;
			lostRadioBtn.labelTxt.textColor = 0xCCCCCC;
			radioContainer.addChild(lostRadioBtn);
			winRadioBtn.selected = true;
			txtTitle = _symbolSkin.txtTitle;
			txtWin = _symbolSkin.txtWin;
			txtTie = _symbolSkin.txtTie;
			txtLose = _symbolSkin.txtLose;
			txtDesc1 = _symbolSkin.txtDesc1;
			txtDesc2 = _symbolSkin.txtDesc2;
			detailBtn1 = _symbolSkin.detailBtn1;
			detailBtn2 = _symbolSkin.detailBtn2;
			//teamDetailPanel = new TeamDetailPanel();
			//teamDetailPanel.initUI();
			addEvtListener();
		}
		/**
		 * 添加事件
		 */		
		public function addEvtListener():void
		{
			sureBtn.addEventListener(MouseEvent.CLICK,sureHandler);
			cashBetBtn.addEventListener(MouseEvent.CLICK,betHandler);
			coinBetBtn.addEventListener(MouseEvent.CLICK,betHandler);
			//detailBtn1.addEventListener(MouseEvent.CLICK,lookTeamDetailHanlder);
			//detailBtn2.addEventListener(MouseEvent.CLICK,lookTeamDetailHanlder);
			this.addEventListener(Event.REMOVED_FROM_STAGE,onRemoveFSHandler);
		}
		/**
		 *确认点击  返回 
		 * @param e
		 * 
		 */		
		private function sureHandler(e :MouseEvent):void
		{
			this.dispatchEvent(new Event("betResultPReturn",true));
		}
		/**
		 *押注 
		 * @param e
		 */		
		private function betHandler(e :MouseEvent):void
		{
			var betValue :int;
			switch(e.target)
			{
				case cashBetBtn://点券
				{
					var cashpoint :int = AppData.getInstance().clubDatamanager.clubInfo.cashpoint;
					betValue = int(txtCashValue.text);
					if(betValue < 10)
					{
						Alert.showErrorTip("最低需押注10点券");
						return;
					}
					if(betValue > 100000)
					{
						Alert.showErrorTip("最高押注不能大于100000点券");
						return;
					}
					if(betValue > cashpoint)
					{
						Alert.showErrorTip("点券不足");
						return;
					}
					isCashBet = true;
					Alert.show("确定投注"+betValue+"点券?","",Alert.YES | Alert.NO,GlobalDef.GameStage,betAlertHandler);
					break;
				}
				case coinBetBtn://欧元
				{
					var coin :int = AppData.getInstance().clubDatamanager.clubInfo.coin;
					betValue = int(txtCoinValue.text);
					if(betValue < 100000)
					{
						Alert.showErrorTip("最低需押注100000欧元");
						return;
					}
					if(betValue > 100000000)
					{
						Alert.showErrorTip("最高押注不能大于100000000欧元");
						return;
					}
					if(betValue > coin)
					{
						Alert.showErrorTip("欧元不足");
						return;
					}
					Alert.show("确定投注"+betValue+"欧元?","",Alert.YES | Alert.NO,GlobalDef.GameStage,betAlertHandler);
					break;
				}
			}
		}
		/**
		 *投注确认 
		 * @param type
		 * 
		 */		
		private function betAlertHandler(type :int):void
		{
			if(type == Alert.YES)
			{
				var cashValue :int = int(txtCashValue.text);
				var coinValue :int = int(txtCoinValue.text);
				if(isCashBet)
				{
					coinValue = 0;
				}
				else
				{
					cashValue = 0;
				}
				var selectRadioBtn :RadioButton = winRadioBtn.group.selection;
				var param:Object = {choice:selectRadioBtn.value,gid:_data.guessid,cash:cashValue,coin:coinValue};
				this.dispatchEvent(new GuessEvent(GuessEvent.Bet,param,true));
			}
			isCashBet = false;
		}
		/**
		 *下注返回 
		 * @param value
		 * 
		 */		
		public function betRes(value:Object):void
		{
			//betMc.mouseChildren = true;
			//betMc.mouseEnabled = true;
		}
		/**
		 * 查看球队详情
		 * @param e
		 * 
		 */		
		private function lookTeamDetailHanlder(e:MouseEvent):void
		{
			PopUpManager.addWindow(teamDetailPanel,GlobalDef.GameContainer,0,0,true);
			switch(e.target)
			{
				case detailBtn1://球队1
				{
					teamDetailPanel.data = _data.desc1;
					break;
				}
				case detailBtn2://球队2
				{
					teamDetailPanel.data = _data.desc2;
					break;
				}
			}
		}
		/**
		 *从舞台删除 
		 * @param e
		 * 
		 */		
		private function onRemoveFSHandler(e :Event):void
		{
			//betMc.visible = false;
		}
		/**
		 * 删除事件
		 */		
		public function removeEvtListener():void
		{
			sureBtn.removeEventListener(MouseEvent.CLICK,sureHandler);
			cashBetBtn.removeEventListener(MouseEvent.CLICK,betHandler);
			coinBetBtn.removeEventListener(MouseEvent.CLICK,betHandler);
			//detailBtn1.removeEventListener(MouseEvent.CLICK,lookTeamDetailHanlder);
			//detailBtn2.removeEventListener(MouseEvent.CLICK,lookTeamDetailHanlder);
			this.removeEventListener(Event.REMOVED_FROM_STAGE,onRemoveFSHandler);
		}
		/**
		 * 销毁
		 */		
		public function destroyView():void
		{
			removeEvtListener();
			//teamDetailPanel.destroyView();
			teamDetailPanel = null;
			_data = null;
		}
	}
}